<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
function foo(){
    var p = {
        name: "李四",
        age: 40
    }
    return {
        getName : function (){
            return p.name;
        },
        getAge : function (){
            return 20;
        },
        setName : function (name){
            p.name = name;
        },
        addAttr : function (key, value){
            p[key] = value;
        },
        getAttr : function (key){
            return p[key];
        }
    }
}
var p = foo()
p.setName("abc")
console.log(p.getName());
p.addAttr("sex", "男");
console.log(p.getAttr("sex"));


</script>

</body>
</html>